﻿<cfsilent>
	<cfscript>
	
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		
		termId = event.getArg("TID");
		courseId = event.getArg("CID");
		taskType = event.getArg("TT");
		taskId = event.getArg("TSK");
		chooserId = event.getArg("SCC");
		
		/* 学籍相关信息 */
		studentId = event.getArg("STU");
		
		/* 回执信息 */
		response = structNew();
		structInsert(response, "success", false, true);
		
		transaction {
			/* 增加选课席位 */
			switch(taskType){
				case "P":
					sql = "	UPDATE
								t_task t
							SET
								t.task_chooesd = t.task_chooesd - 1
							WHERE
								t.tsk_id = :taskId ";
					break;
				case "R":
					sql = "	UPDATE
								t_reopen_task t
							SET
								t.task_chooesd = t.task_chooesd - 1
							WHERE
								t.tsk_id = :taskId ";
					break;
				case "C":
					sql = "	UPDATE
								t_common_task t
							SET
								t.task_chooesd = t.task_chooesd - 1
							WHERE
								t.tsk_id = :taskId ";
					break;
				case "T":
					sql = "	UPDATE
								t_sport_task t
							SET
								t.task_chooesd = t.task_chooesd - 1
							WHERE
								t.tsk_id = :taskId ";
					break;
			}
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "taskId", value = taskId, cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			
			
			/* 删除选课记录 */
			sql = "	DELETE FROM
						t_student_course sc
					WHERE
						sc.scc_id = :chooserId ";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "chooserId", value = chooserId, cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			/* 删除考试安排 */
			sql = "	DELETE FROM
						t_student_exam t
					WHERE
						t.scc_id = :chooserId ";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "chooserId", value = chooserId, cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			/* 删除成绩临时记录 */
			sql = "	DELETE FROM
						t_temp_mark t
					WHERE
						t.scc_id = :chooserId ";
			
			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "chooserId", value = chooserId, cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			/* 删除对应成绩记录 */
			sql = "	DELETE FROM
						t_student_mark t
					WHERE
						t.scc_id = :chooserId ";

			queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "chooserId", value = chooserId, cfsqltype = "cf_sql_varchar");
			queryObj.execute(sql = sql);
			
			structInsert(response, "success", true, true);
			
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>